package jk.fox.spring.bootstrap;

import jk.fox.spring.config.FoxRpcConfigurationProperties;
import jk.fox.engine.RpcEngine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * @author cuichao
 * @Description: RpcSpringApplicationRunListener
 * @Date: create in 2020/6/1 10:12
 */
public class RpcSpringApplicationRunListener implements SpringApplicationRunListener {
    private SpringApplication application;
    private String[] args;

    public RpcSpringApplicationRunListener(SpringApplication application, String[]  args){
        this.application = application;
        this.args = args;
    }

    @Override
    public void running(ConfigurableApplicationContext context) {
        RpcEngine bean = context.getBean(RpcEngine.class);
        FoxRpcConfigurationProperties properties = context.getBean(FoxRpcConfigurationProperties.class);
        if(!properties.isEnable()){
            return;
        }
        try {
            bean.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
